package com.wdy.delegate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

/**
 * @ClassName: BusinessDelegate
 * @Description: TODO
 * @Date: 2019/12/31 16:23
 * @Author: wangdy001
 * @Version: 1.0
 */
public class BusinessDelegate {
    private static final Logger LOG = LoggerFactory.getLogger(BusinessDelegate.class);

    private ServiceType serviceType;

    public void setServiceType(ServiceType serviceType) {
        this.serviceType = serviceType;
    }

    public void doTask(){
        Optional<BusinessService> businessService = ServiceLookup.getBusinessService(serviceType);
        if(businessService.isPresent()) {
            LOG.error("BusinessDelegate ServiceLookup find {}, serviceType={}", businessService.get(), serviceType);
            businessService.ifPresent(service ->  service.doProcessing());
        } else {
            LOG.error("BusinessDelegate ServiceLookup find null, serviceType={}", serviceType);
        }
    }
}
